import java.util.Scanner;

public class Solution1 {
    //DP41 【模板】01背包
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int V = in.nextInt();
        int[] v = new int[n];
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = in.nextInt();
            w[i] = in.nextInt();
        }

        int[] dp = new int[V+1];//dp[i][j]表示前i个物品，容量不大于j 的最大价值
        int[] dp2  =new int[V+1];

        for (int i = 1; i < V+1; i++) {
            dp2[i] = -1;
        }
        for (int i = 1; i < n+1; i++) {
            for (int j = V; j >= v[i-1]; j--) {


                dp[j] = Math.max(dp[j],w[i-1] + dp[j-v[i-1]]);

                if (dp2[j-v[i-1]] != -1) {
                    dp2[j] = Math.max(dp2[j],w[i-1] + dp2[j-v[i-1]]);
                }
            }
        }

        System.out.println(dp[V]);
        dp2[V] =  dp2[V] == -1 ? 0 : dp2[V];
        System.out.println(dp2[V]);
    }
}
